﻿using Microsoft.AspNetCore.Mvc.Filters;
using System.Threading.Tasks;

namespace youzackcom.ExceptionFillter
{
    /// <summary>
    /// 自定义Abp异常
    /// </summary>
    //[Dependency(ReplaceServices = true)]
    public class CustomExceptionFilter : IAsyncExceptionFilter //, ITransientDependency
    {
        public virtual async Task OnExceptionAsync(ExceptionContext context)
        {
            //context.Exception = new Exception("你好啊");
            //return Task.CompletedTask;
            //捕获异常
            //if (context.Exception is BusinessException)
            //{
            //    context.Result = new ObjectResult(new
            //    {
            //        code = "-1", //自定义错误代码
            //        message = context.Exception.Message,
            //        details = context.Exception.StackTrace
            //    })
            //    {
            //        StatusCode = StatusCodes.Status500InternalServerError
            //    };
            //    //不标记处理会进入到abp自带的异常处理过滤器
            //    context.ExceptionHandled = true; //标记异常已处理
            //}
            //return Task.CompletedTask;
        }
    }
}
